package cn.com.nxt.txb.util;

import android.content.Context;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.inputmethodservice.KeyboardView.OnKeyboardActionListener;
import android.text.Editable;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import cn.com.nxt.txb.R;

public class KeyboardUtil {
    private KeyboardView keyboardView;
    private EditText editText;
    private Keyboard k1;// 字母键盘
    private OnKeyboardActionListener listener;

    public KeyboardUtil(OnKeyboardActionListener listener,KeyboardView keyboardView1, EditText editText) {
        super();
        this.listener=listener;
        keyboardView = keyboardView1;
        this.editText = editText;
        keyboardView.setOnKeyboardActionListener(listener);
        k1 = new Keyboard(editText.getContext(), R.xml.keyboard_call);
        keyboardView.setKeyboard(k1);
        keyboardView.setEnabled(true);
        keyboardView.setPreviewEnabled(true);
    }

    // Activity中获取焦点时调用，显示出键盘
    public void showKeyboard() {
        int visibility = keyboardView.getVisibility();
        if (visibility == View.GONE || visibility == View.INVISIBLE) {
            keyboardView.setVisibility(View.VISIBLE);
        }
    }

    // 隐藏键盘
    public void hiddleKeyboard() {
        int visibility = keyboardView.getVisibility();
        if (visibility == View.VISIBLE) {
            keyboardView.setVisibility(View.GONE);
        }
    }
}
